<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>API: treeview   Node.js  (YUI Library)</title>
	<link rel="stylesheet" type="text/css" href="assets/api.css">
</head>

<body id="yahoo-com">
<div id="doc3" class="yui-t2">

	<div id="hd">
        <h1>Yahoo! UI Library</h1>
        <h3>TreeView Widget&nbsp; <span class="subtitle">2.2.2</span></h3>
        <p>
        <a href="./index.html">Yahoo! UI Library</a> 
            &gt; <a href="./module_treeview.html">treeview</a>
                
                 &gt; Node.js (source view) 
            </p>
	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">

                    <div id="srcout">
<div class="highlight" ><pre><span class="c">/**</span>
<span class="c"> * The base class for all tree nodes.  The node&#39;s presentation and behavior in</span>
<span class="c"> * response to mouse events is handled in Node subclasses.</span>
<span class="c"> * @namespace YAHOO.widget</span>
<span class="c"> * @class Node</span>
<span class="c"> * @uses YAHOO.util.EventProvider</span>
<span class="c"> * @param oData {object} a string or object containing the data that will</span>
<span class="c"> * be used to render this node</span>
<span class="c"> * @param oParent {Node} this node&#39;s parent node</span>
<span class="c"> * @param expanded {boolean} the initial expanded/collapsed state</span>
<span class="c"> * @constructor</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">Node</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">oData</span><span class="o">,</span> <span class="nx">oParent</span><span class="o">,</span> <span class="nx">expanded</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">if</span> <span class="o">(</span><span class="nx">oData</span><span class="o">)</span> <span class="o">{</span> <span class="k">this</span><span class="o">.</span><span class="nx">init</span><span class="o">(</span><span class="nx">oData</span><span class="o">,</span> <span class="nx">oParent</span><span class="o">,</span> <span class="nx">expanded</span><span class="o">);</span> <span class="o">}</span>
<span class="o">};</span>

<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="o">{</span>

    <span class="c">/**</span>
<span class="c">     * The index for this instance obtained from global counter in YAHOO.widget.TreeView.</span>
<span class="c">     * @property index</span>
<span class="c">     * @type int</span>
<span class="c">     */</span>
    <span class="nx">index</span><span class="o">:</span> <span class="m">0</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * This node&#39;s child node collection.</span>
<span class="c">     * @property children</span>
<span class="c">     * @type Node[] </span>
<span class="c">     */</span>
    <span class="nx">children</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * Tree instance this node is part of</span>
<span class="c">     * @property tree</span>
<span class="c">     * @type TreeView</span>
<span class="c">     */</span>
    <span class="nx">tree</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * The data linked to this node.  This can be any object or primitive</span>
<span class="c">     * value, and the data can be used in getNodeHtml().</span>
<span class="c">     * @property data</span>
<span class="c">     * @type object</span>
<span class="c">     */</span>
    <span class="nx">data</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * Parent node</span>
<span class="c">     * @property parent</span>
<span class="c">     * @type Node</span>
<span class="c">     */</span>
    <span class="nx">parent</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * The depth of this node.  We start at -1 for the root node.</span>
<span class="c">     * @property depth</span>
<span class="c">     * @type int</span>
<span class="c">     */</span>
    <span class="nx">depth</span><span class="o">:</span> <span class="o">-</span><span class="m">1</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * The href for the node&#39;s label.  If one is not specified, the href will</span>
<span class="c">     * be set so that it toggles the node.</span>
<span class="c">     * @property href</span>
<span class="c">     * @type string</span>
<span class="c">     */</span>
    <span class="nx">href</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * The label href target, defaults to current window</span>
<span class="c">     * @property target</span>
<span class="c">     * @type string</span>
<span class="c">     */</span>
    <span class="nx">target</span><span class="o">:</span> <span class="s2">&quot;_self&quot;</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * The node&#39;s expanded/collapsed state</span>
<span class="c">     * @property expanded</span>
<span class="c">     * @type boolean</span>
<span class="c">     */</span>
    <span class="nx">expanded</span><span class="o">:</span> <span class="kc">false</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * Can multiple children be expanded at once?</span>
<span class="c">     * @property multiExpand</span>
<span class="c">     * @type boolean</span>
<span class="c">     */</span>
    <span class="nx">multiExpand</span><span class="o">:</span> <span class="kc">true</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * Should we render children for a collapsed node?  It is possible that the</span>
<span class="c">     * implementer will want to render the hidden data...  @todo verify that we </span>
<span class="c">     * need this, and implement it if we do.</span>
<span class="c">     * @property renderHidden</span>
<span class="c">     * @type boolean</span>
<span class="c">     */</span>
    <span class="nx">renderHidden</span><span class="o">:</span> <span class="kc">false</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * This flag is set to true when the html is generated for this node&#39;s</span>
<span class="c">     * children, and set to false when new children are added.</span>
<span class="c">     * @property childrenRendered</span>
<span class="c">     * @type boolean</span>
<span class="c">     */</span>
    <span class="nx">childrenRendered</span><span class="o">:</span> <span class="kc">false</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * Dynamically loaded nodes only fetch the data the first time they are</span>
<span class="c">     * expanded.  This flag is set to true once the data has been fetched.</span>
<span class="c">     * @property dynamicLoadComplete</span>
<span class="c">     * @type boolean</span>
<span class="c">     */</span>
    <span class="nx">dynamicLoadComplete</span><span class="o">:</span> <span class="kc">false</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * This node&#39;s previous sibling</span>
<span class="c">     * @property previousSibling</span>
<span class="c">     * @type Node</span>
<span class="c">     */</span>
    <span class="nx">previousSibling</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * This node&#39;s next sibling</span>
<span class="c">     * @property nextSibling</span>
<span class="c">     * @type Node</span>
<span class="c">     */</span>
    <span class="nx">nextSibling</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * We can set the node up to call an external method to get the child</span>
<span class="c">     * data dynamically.</span>
<span class="c">     * @property _dynLoad</span>
<span class="c">     * @type boolean</span>
<span class="c">     * @private</span>
<span class="c">     */</span>
    <span class="nx">_dynLoad</span><span class="o">:</span> <span class="kc">false</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * Function to execute when we need to get this node&#39;s child data.</span>
<span class="c">     * @property dataLoader</span>
<span class="c">     * @type function</span>
<span class="c">     */</span>
    <span class="nx">dataLoader</span><span class="o">:</span> <span class="kc">null</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * This is true for dynamically loading nodes while waiting for the</span>
<span class="c">     * callback to return.</span>
<span class="c">     * @property isLoading</span>
<span class="c">     * @type boolean</span>
<span class="c">     */</span>
    <span class="nx">isLoading</span><span class="o">:</span> <span class="kc">false</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * The toggle/branch icon will not show if this is set to false.  This</span>
<span class="c">     * could be useful if the implementer wants to have the child contain</span>
<span class="c">     * extra info about the parent, rather than an actual node.</span>
<span class="c">     * @property hasIcon</span>
<span class="c">     * @type boolean</span>
<span class="c">     */</span>
    <span class="nx">hasIcon</span><span class="o">:</span> <span class="kc">true</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * Used to configure what happens when a dynamic load node is expanded</span>
<span class="c">     * and we discover that it does not have children.  By default, it is</span>
<span class="c">     * treated as if it still could have children (plus/minus icon).  Set</span>
<span class="c">     * iconMode to have it display like a leaf node instead.</span>
<span class="c">     * @property iconMode</span>
<span class="c">     * @type int</span>
<span class="c">     */</span>
    <span class="nx">iconMode</span><span class="o">:</span> <span class="m">0</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * Specifies whether or not the content area of the node should be allowed</span>
<span class="c">     * to wrap.</span>
<span class="c">     * @property nowrap</span>
<span class="c">     * @type boolean</span>
<span class="c">     * @default false</span>
<span class="c">     */</span>
    <span class="nx">nowrap</span><span class="o">:</span> <span class="kc">false</span><span class="o">,</span>

    <span class="c">/**</span>
<span class="c">     * The node type</span>
<span class="c">     * @property _type</span>
<span class="c">     * @private</span>
<span class="c">     */</span>
    <span class="nx">_type</span><span class="o">:</span> <span class="s2">&quot;Node&quot;</span><span class="o">,</span>

    <span class="c">/*</span>
<span class="c">    spacerPath: &quot;http://us.i1.yimg.com/us.yimg.com/i/space.gif&quot;,</span>
<span class="c">    expandedText: &quot;Expanded&quot;,</span>
<span class="c">    collapsedText: &quot;Collapsed&quot;,</span>
<span class="c">    loadingText: &quot;Loading&quot;,</span>
<span class="c">    */</span>

    <span class="c">/**</span>
<span class="c">     * Initializes this node, gets some of the properties from the parent</span>
<span class="c">     * @method init</span>
<span class="c">     * @param oData {object} a string or object containing the data that will</span>
<span class="c">     * be used to render this node</span>
<span class="c">     * @param oParent {Node} this node&#39;s parent node</span>
<span class="c">     * @param expanded {boolean} the initial expanded/collapsed state</span>
<span class="c">     */</span>
    <span class="nx">init</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">oData</span><span class="o">,</span> <span class="nx">oParent</span><span class="o">,</span> <span class="nx">expanded</span><span class="o">)</span> <span class="o">{</span>

        <span class="k">this</span><span class="o">.</span><span class="nx">data</span>       <span class="o">=</span> <span class="nx">oData</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">children</span>   <span class="o">=</span> <span class="o">[];</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">index</span>      <span class="o">=</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">TreeView</span><span class="o">.</span><span class="nx">nodeCount</span><span class="o">;</span>
        <span class="o">++</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">TreeView</span><span class="o">.</span><span class="nx">nodeCount</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">expanded</span>   <span class="o">=</span> <span class="nx">expanded</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">logger</span>     <span class="o">=</span> <span class="k">new</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">LogWriter</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">toString</span><span class="o">());</span>

        <span class="c">/**</span>
<span class="c">         * The parentChange event is fired when a parent element is applied</span>
<span class="c">         * to the node.  This is useful if you need to apply tree-level</span>
<span class="c">         * properties to a tree that need to happen if a node is moved from</span>
<span class="c">         * one tree to another.</span>
<span class="c">         *</span>
<span class="c">         * @event parentChange</span>
<span class="c">         * @type CustomEvent</span>
<span class="c">         */</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">createEvent</span><span class="o">(</span><span class="s2">&quot;parentChange&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>

        <span class="c">// oParent should never be null except when we create the root node.</span>
<span class="c"></span>        <span class="k">if</span> <span class="o">(</span><span class="nx">oParent</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">oParent</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
        <span class="o">}</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Certain properties for the node cannot be set until the parent</span>
<span class="c">     * is known. This is called after the node is inserted into a tree.</span>
<span class="c">     * the parent is also applied to this node&#39;s children in order to</span>
<span class="c">     * make it possible to move a branch from one tree to another.</span>
<span class="c">     * @method applyParent</span>
<span class="c">     * @param {Node} parentNode this node&#39;s parent node</span>
<span class="c">     * @return {boolean} true if the application was successful</span>
<span class="c">     */</span>
    <span class="nx">applyParent</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">parentNode</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(!</span><span class="nx">parentNode</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="k">this</span><span class="o">.</span><span class="nx">tree</span>   <span class="o">=</span> <span class="nx">parentNode</span><span class="o">.</span><span class="nx">tree</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">parent</span> <span class="o">=</span> <span class="nx">parentNode</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">depth</span>  <span class="o">=</span> <span class="nx">parentNode</span><span class="o">.</span><span class="nx">depth</span> <span class="o">+</span> <span class="m">1</span><span class="o">;</span>

        <span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">href</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">href</span> <span class="o">=</span> <span class="s2">&quot;javascript:&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">getToggleLink</span><span class="o">();</span>
        <span class="o">}</span>

        <span class="c">// @todo why was this put here.  This causes new nodes added at the</span>
<span class="c"></span>        <span class="c">// root level to lose the menu behavior.</span>
<span class="c"></span>        <span class="c">// if (! this.multiExpand) {</span>
<span class="c"></span>            <span class="c">// this.multiExpand = parentNode.multiExpand;</span>
<span class="c"></span>        <span class="c">// }</span>
<span class="c"></span>
        <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">regNode</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
        <span class="nx">parentNode</span><span class="o">.</span><span class="nx">childrenRendered</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

        <span class="c">// cascade update existing children</span>
<span class="c"></span>        <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">,</span> <span class="nx">len</span><span class="o">=</span><span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span><span class="nx">i</span><span class="o">&lt;</span><span class="nx">len</span><span class="o">;++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">applyParent</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
        <span class="o">}</span>

        <span class="k">this</span><span class="o">.</span><span class="nx">fireEvent</span><span class="o">(</span><span class="s2">&quot;parentChange&quot;</span><span class="o">);</span>

        <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Appends a node to the child collection.</span>
<span class="c">     * @method appendChild</span>
<span class="c">     * @param childNode {Node} the new node</span>
<span class="c">     * @return {Node} the child node</span>
<span class="c">     * @private</span>
<span class="c">     */</span>
    <span class="nx">appendChild</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">childNode</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">hasChildren</span><span class="o">())</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">sib</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">.</span><span class="nx">length</span> <span class="o">-</span> <span class="m">1</span><span class="o">];</span>
            <span class="nx">sib</span><span class="o">.</span><span class="nx">nextSibling</span> <span class="o">=</span> <span class="nx">childNode</span><span class="o">;</span>
            <span class="nx">childNode</span><span class="o">.</span><span class="nx">previousSibling</span> <span class="o">=</span> <span class="nx">sib</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="nx">childNode</span><span class="o">;</span>
        <span class="nx">childNode</span><span class="o">.</span><span class="nx">applyParent</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>

        <span class="k">return</span> <span class="nx">childNode</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Appends this node to the supplied node&#39;s child collection</span>
<span class="c">     * @method appendTo</span>
<span class="c">     * @param parentNode {Node} the node to append to.</span>
<span class="c">     * @return {Node} The appended node</span>
<span class="c">     */</span>
    <span class="nx">appendTo</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">parentNode</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span> <span class="nx">parentNode</span><span class="o">.</span><span class="nx">appendChild</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">    * Inserts this node before this supplied node</span>
<span class="c">    * @method insertBefore</span>
<span class="c">    * @param node {Node} the node to insert this node before</span>
<span class="c">    * @return {Node} the inserted node</span>
<span class="c">    */</span>
    <span class="nx">insertBefore</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;insertBefore: &quot;</span> <span class="o">+</span> <span class="nx">node</span><span class="o">);</span>
        <span class="k">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="nx">node</span><span class="o">.</span><span class="nx">parent</span><span class="o">;</span>
        <span class="k">if</span> <span class="o">(</span><span class="nx">p</span><span class="o">)</span> <span class="o">{</span>

            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">popNode</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
            <span class="o">}</span>

            <span class="k">var</span> <span class="nx">refIndex</span> <span class="o">=</span> <span class="nx">node</span><span class="o">.</span><span class="nx">isChildOf</span><span class="o">(</span><span class="nx">p</span><span class="o">);</span>
            <span class="c">//this.logger.log(refIndex);</span>
<span class="c"></span>            <span class="nx">p</span><span class="o">.</span><span class="nx">children</span><span class="o">.</span><span class="nx">splice</span><span class="o">(</span><span class="nx">refIndex</span><span class="o">,</span> <span class="m">0</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
            <span class="k">if</span> <span class="o">(</span><span class="nx">node</span><span class="o">.</span><span class="nx">previousSibling</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">node</span><span class="o">.</span><span class="nx">previousSibling</span><span class="o">.</span><span class="nx">nextSibling</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
            <span class="o">}</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">previousSibling</span> <span class="o">=</span> <span class="nx">node</span><span class="o">.</span><span class="nx">previousSibling</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">nextSibling</span> <span class="o">=</span> <span class="nx">node</span><span class="o">;</span>
            <span class="nx">node</span><span class="o">.</span><span class="nx">previousSibling</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>

            <span class="k">this</span><span class="o">.</span><span class="nx">applyParent</span><span class="o">(</span><span class="nx">p</span><span class="o">);</span>
        <span class="o">}</span>

        <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
    <span class="o">},</span>
 
    <span class="c">/**</span>
<span class="c">    * Inserts this node after the supplied node</span>
<span class="c">    * @method insertAfter</span>
<span class="c">    * @param node {Node} the node to insert after</span>
<span class="c">    * @return {Node} the inserted node</span>
<span class="c">    */</span>
    <span class="nx">insertAfter</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;insertAfter: &quot;</span> <span class="o">+</span> <span class="nx">node</span><span class="o">);</span>
        <span class="k">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="nx">node</span><span class="o">.</span><span class="nx">parent</span><span class="o">;</span>
        <span class="k">if</span> <span class="o">(</span><span class="nx">p</span><span class="o">)</span> <span class="o">{</span>

            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">popNode</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
            <span class="o">}</span>

            <span class="k">var</span> <span class="nx">refIndex</span> <span class="o">=</span> <span class="nx">node</span><span class="o">.</span><span class="nx">isChildOf</span><span class="o">(</span><span class="nx">p</span><span class="o">);</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="nx">refIndex</span><span class="o">);</span>

            <span class="k">if</span> <span class="o">(!</span><span class="nx">node</span><span class="o">.</span><span class="nx">nextSibling</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">this</span><span class="o">.</span><span class="nx">nextSibling</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
                <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">appendTo</span><span class="o">(</span><span class="nx">p</span><span class="o">);</span>
            <span class="o">}</span>

            <span class="nx">p</span><span class="o">.</span><span class="nx">children</span><span class="o">.</span><span class="nx">splice</span><span class="o">(</span><span class="nx">refIndex</span> <span class="o">+</span> <span class="m">1</span><span class="o">,</span> <span class="m">0</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>

            <span class="nx">node</span><span class="o">.</span><span class="nx">nextSibling</span><span class="o">.</span><span class="nx">previousSibling</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">previousSibling</span> <span class="o">=</span> <span class="nx">node</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">nextSibling</span> <span class="o">=</span> <span class="nx">node</span><span class="o">.</span><span class="nx">nextSibling</span><span class="o">;</span>
            <span class="nx">node</span><span class="o">.</span><span class="nx">nextSibling</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>

            <span class="k">this</span><span class="o">.</span><span class="nx">applyParent</span><span class="o">(</span><span class="nx">p</span><span class="o">);</span>
        <span class="o">}</span>

        <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">    * Returns true if the Node is a child of supplied Node</span>
<span class="c">    * @method isChildOf</span>
<span class="c">    * @param parentNode {Node} the Node to check</span>
<span class="c">    * @return {boolean} The node index if this Node is a child of </span>
<span class="c">    *                   supplied Node, else -1.</span>
<span class="c">    * @private</span>
<span class="c">    */</span>
    <span class="nx">isChildOf</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">parentNode</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(</span><span class="nx">parentNode</span> <span class="o">&amp;&amp;</span> <span class="nx">parentNode</span><span class="o">.</span><span class="nx">children</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">,</span> <span class="nx">len</span><span class="o">=</span><span class="nx">parentNode</span><span class="o">.</span><span class="nx">children</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">len</span> <span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">if</span> <span class="o">(</span><span class="nx">parentNode</span><span class="o">.</span><span class="nx">children</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">===</span> <span class="k">this</span><span class="o">)</span> <span class="o">{</span>
                    <span class="k">return</span> <span class="nx">i</span><span class="o">;</span>
                <span class="o">}</span>
            <span class="o">}</span>
        <span class="o">}</span>

        <span class="k">return</span> <span class="o">-</span><span class="m">1</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns a node array of this node&#39;s siblings, null if none.</span>
<span class="c">     * @method getSiblings</span>
<span class="c">     * @return Node[]</span>
<span class="c">     */</span>
    <span class="nx">getSiblings</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">parent</span><span class="o">.</span><span class="nx">children</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Shows this node&#39;s children</span>
<span class="c">     * @method showChildren</span>
<span class="c">     */</span>
    <span class="nx">showChildren</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">animateExpand</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">getChildrenEl</span><span class="o">(),</span> <span class="k">this</span><span class="o">))</span> <span class="o">{</span>
            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">hasChildren</span><span class="o">())</span> <span class="o">{</span>
                <span class="k">this</span><span class="o">.</span><span class="nx">getChildrenEl</span><span class="o">().</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">;</span>
            <span class="o">}</span>
        <span class="o">}</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Hides this node&#39;s children</span>
<span class="c">     * @method hideChildren</span>
<span class="c">     */</span>
    <span class="nx">hideChildren</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;hiding &quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">index</span><span class="o">);</span>

        <span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">animateCollapse</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">getChildrenEl</span><span class="o">(),</span> <span class="k">this</span><span class="o">))</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">getChildrenEl</span><span class="o">().</span><span class="nx">style</span><span class="o">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s2">&quot;none&quot;</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns the id for this node&#39;s container div</span>
<span class="c">     * @method getElId</span>
<span class="c">     * @return {string} the element id</span>
<span class="c">     */</span>
    <span class="nx">getElId</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="s2">&quot;ygtv&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">index</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns the id for this node&#39;s children div</span>
<span class="c">     * @method getChildrenElId</span>
<span class="c">     * @return {string} the element id for this node&#39;s children div</span>
<span class="c">     */</span>
    <span class="nx">getChildrenElId</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="s2">&quot;ygtvc&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">index</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns the id for this node&#39;s toggle element</span>
<span class="c">     * @method getToggleElId</span>
<span class="c">     * @return {string} the toggel element id</span>
<span class="c">     */</span>
    <span class="nx">getToggleElId</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="s2">&quot;ygtvt&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">index</span><span class="o">;</span>
    <span class="o">},</span>


    <span class="c">/*</span>
<span class="c">     * Returns the id for this node&#39;s spacer image.  The spacer is positioned</span>
<span class="c">     * over the toggle and provides feedback for screen readers.</span>
<span class="c">     * @method getSpacerId</span>
<span class="c">     * @return {string} the id for the spacer image</span>
<span class="c">     */</span>
    <span class="c">/*</span>
<span class="c">    getSpacerId: function() {</span>
<span class="c">        return &quot;ygtvspacer&quot; + this.index;</span>
<span class="c">    }, </span>
<span class="c">    */</span>

    <span class="c">/**</span>
<span class="c">     * Returns this node&#39;s container html element</span>
<span class="c">     * @method getEl</span>
<span class="c">     * @return {HTMLElement} the container html element</span>
<span class="c">     */</span>
    <span class="nx">getEl</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="nb">document</span><span class="o">.</span><span class="nx">getElementById</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">getElId</span><span class="o">());</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns the div that was generated for this node&#39;s children</span>
<span class="c">     * @method getChildrenEl</span>
<span class="c">     * @return {HTMLElement} this node&#39;s children div</span>
<span class="c">     */</span>
    <span class="nx">getChildrenEl</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="nb">document</span><span class="o">.</span><span class="nx">getElementById</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">getChildrenElId</span><span class="o">());</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns the element that is being used for this node&#39;s toggle.</span>
<span class="c">     * @method getToggleEl</span>
<span class="c">     * @return {HTMLElement} this node&#39;s toggle html element</span>
<span class="c">     */</span>
    <span class="nx">getToggleEl</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="nb">document</span><span class="o">.</span><span class="nx">getElementById</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">getToggleElId</span><span class="o">());</span>
    <span class="o">},</span>

    <span class="c">/*</span>
<span class="c">     * Returns the element that is being used for this node&#39;s spacer.</span>
<span class="c">     * @method getSpacer</span>
<span class="c">     * @return {HTMLElement} this node&#39;s spacer html element</span>
<span class="c">     */</span>
    <span class="c">/*</span>
<span class="c">    getSpacer: function() {</span>
<span class="c">        return document.getElementById( this.getSpacerId() ) || {};</span>
<span class="c">    },</span>
<span class="c">    */</span>

    <span class="c">/*</span>
<span class="c">    getStateText: function() {</span>
<span class="c">        if (this.isLoading) {</span>
<span class="c">            return this.loadingText;</span>
<span class="c">        } else if (this.hasChildren(true)) {</span>
<span class="c">            if (this.expanded) {</span>
<span class="c">                return this.expandedText;</span>
<span class="c">            } else {</span>
<span class="c">                return this.collapsedText;</span>
<span class="c">            }</span>
<span class="c">        } else {</span>
<span class="c">            return &quot;&quot;;</span>
<span class="c">        }</span>
<span class="c">    },</span>
<span class="c">    */</span>

    <span class="c">/**</span>
<span class="c">     * Generates the link that will invoke this node&#39;s toggle method</span>
<span class="c">     * @method getToggleLink</span>
<span class="c">     * @return {string} the javascript url for toggling this node</span>
<span class="c">     */</span>
    <span class="nx">getToggleLink</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="s2">&quot;YAHOO.widget.TreeView.getNode(\&#39;&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">id</span> <span class="o">+</span> <span class="s2">&quot;\&#39;,&quot;</span> <span class="o">+</span> 
            <span class="k">this</span><span class="o">.</span><span class="nx">index</span> <span class="o">+</span> <span class="s2">&quot;).toggle()&quot;</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Hides this nodes children (creating them if necessary), changes the</span>
<span class="c">     * @method collapse</span>
<span class="c">     * toggle style.</span>
<span class="c">     */</span>
    <span class="nx">collapse</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="c">// Only collapse if currently expanded</span>
<span class="c"></span>        <span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">expanded</span><span class="o">)</span> <span class="o">{</span> <span class="k">return</span><span class="o">;</span> <span class="o">}</span>

        <span class="c">// fire the collapse event handler</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">onCollapse</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>

        <span class="k">if</span> <span class="o">(</span><span class="kc">false</span> <span class="o">===</span> <span class="nx">ret</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Collapse was stopped by the abstract onCollapse&quot;</span><span class="o">);</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="nx">ret</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">fireEvent</span><span class="o">(</span><span class="s2">&quot;collapse&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>

        <span class="k">if</span> <span class="o">(</span><span class="kc">false</span> <span class="o">===</span> <span class="nx">ret</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Collapse was stopped by a custom event handler&quot;</span><span class="o">);</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>


        <span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">getEl</span><span class="o">())</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">expanded</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
        <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
            <span class="c">// hide the child div</span>
<span class="c"></span>            <span class="k">this</span><span class="o">.</span><span class="nx">hideChildren</span><span class="o">();</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">expanded</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

            <span class="k">this</span><span class="o">.</span><span class="nx">updateIcon</span><span class="o">();</span>
        <span class="o">}</span>

        <span class="c">// this.getSpacer().title = this.getStateText();</span>
<span class="c"></span>
        <span class="nx">ret</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">fireEvent</span><span class="o">(</span><span class="s2">&quot;collapseComplete&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>

    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Shows this nodes children (creating them if necessary), changes the</span>
<span class="c">     * toggle style, and collapses its siblings if multiExpand is not set.</span>
<span class="c">     * @method expand</span>
<span class="c">     */</span>
    <span class="nx">expand</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="c">// Only expand if currently collapsed.</span>
<span class="c"></span>        <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">expanded</span><span class="o">)</span> <span class="o">{</span> <span class="k">return</span><span class="o">;</span> <span class="o">}</span>

        <span class="c">// fire the expand event handler</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">onExpand</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>

        <span class="k">if</span> <span class="o">(</span><span class="kc">false</span> <span class="o">===</span> <span class="nx">ret</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Expand was stopped by the abstract onExpand&quot;</span><span class="o">);</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>
        
        <span class="nx">ret</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">fireEvent</span><span class="o">(</span><span class="s2">&quot;expand&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>

        <span class="k">if</span> <span class="o">(</span><span class="kc">false</span> <span class="o">===</span> <span class="nx">ret</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Expand was stopped by the custom event handler&quot;</span><span class="o">);</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">getEl</span><span class="o">())</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">expanded</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="k">if</span> <span class="o">(!</span> <span class="k">this</span><span class="o">.</span><span class="nx">childrenRendered</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;children not rendered yet&quot;</span><span class="o">);</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">getChildrenEl</span><span class="o">().</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">renderChildren</span><span class="o">();</span>
        <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;CHILDREN RENDERED&quot;</span><span class="o">);</span>
        <span class="o">}</span>

        <span class="k">this</span><span class="o">.</span><span class="nx">expanded</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>

        <span class="k">this</span><span class="o">.</span><span class="nx">updateIcon</span><span class="o">();</span>

        <span class="c">// this.getSpacer().title = this.getStateText();</span>
<span class="c"></span>
        <span class="c">// We do an extra check for children here because the lazy</span>
<span class="c"></span>        <span class="c">// load feature can expose nodes that have no children.</span>
<span class="c"></span>
        <span class="c">// if (!this.hasChildren()) {</span>
<span class="c"></span>        <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">isLoading</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">expanded</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
            <span class="k">return</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="k">if</span> <span class="o">(!</span> <span class="k">this</span><span class="o">.</span><span class="nx">multiExpand</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">sibs</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">getSiblings</span><span class="o">();</span>
            <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">sibs</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">if</span> <span class="o">(</span><span class="nx">sibs</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">!=</span> <span class="k">this</span> <span class="o">&amp;&amp;</span> <span class="nx">sibs</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">expanded</span><span class="o">)</span> <span class="o">{</span> 
                    <span class="nx">sibs</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">collapse</span><span class="o">();</span> 
                <span class="o">}</span>
            <span class="o">}</span>
        <span class="o">}</span>

        <span class="k">this</span><span class="o">.</span><span class="nx">showChildren</span><span class="o">();</span>

        <span class="nx">ret</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">fireEvent</span><span class="o">(</span><span class="s2">&quot;expandComplete&quot;</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
    <span class="o">},</span>

    <span class="nx">updateIcon</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">hasIcon</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">el</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">getToggleEl</span><span class="o">();</span>
            <span class="k">if</span> <span class="o">(</span><span class="nx">el</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">el</span><span class="o">.</span><span class="nx">className</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">getStyle</span><span class="o">();</span>
            <span class="o">}</span>
        <span class="o">}</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns the css style name for the toggle</span>
<span class="c">     * @method getStyle</span>
<span class="c">     * @return {string} the css class for this node&#39;s toggle</span>
<span class="c">     */</span>
    <span class="nx">getStyle</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="c">// this.logger.log(&quot;No children, &quot; + &quot; isDyanmic: &quot; + this.isDynamic() + &quot; expanded: &quot; + this.expanded);</span>
<span class="c"></span>        <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">isLoading</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;returning the loading icon&quot;</span><span class="o">);</span>
            <span class="k">return</span> <span class="s2">&quot;ygtvloading&quot;</span><span class="o">;</span>
        <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
            <span class="c">// location top or bottom, middle nodes also get the top style</span>
<span class="c"></span>            <span class="k">var</span> <span class="nx">loc</span> <span class="o">=</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">nextSibling</span><span class="o">)</span> <span class="o">?</span> <span class="s2">&quot;t&quot;</span> <span class="o">:</span> <span class="s2">&quot;l&quot;</span><span class="o">;</span>

            <span class="c">// type p=plus(expand), m=minus(collapase), n=none(no children)</span>
<span class="c"></span>            <span class="k">var</span> <span class="nx">type</span> <span class="o">=</span> <span class="s2">&quot;n&quot;</span><span class="o">;</span>
            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">hasChildren</span><span class="o">(</span><span class="kc">true</span><span class="o">)</span> <span class="o">||</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">isDynamic</span><span class="o">()</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="o">.</span><span class="nx">getIconMode</span><span class="o">()))</span> <span class="o">{</span>
            <span class="c">// if (this.hasChildren(true)) {</span>
<span class="c"></span>                <span class="nx">type</span> <span class="o">=</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">expanded</span><span class="o">)</span> <span class="o">?</span> <span class="s2">&quot;m&quot;</span> <span class="o">:</span> <span class="s2">&quot;p&quot;</span><span class="o">;</span>
            <span class="o">}</span>

            <span class="c">// this.logger.log(&quot;ygtv&quot; + loc + type);</span>
<span class="c"></span>            <span class="k">return</span> <span class="s2">&quot;ygtv&quot;</span> <span class="o">+</span> <span class="nx">loc</span> <span class="o">+</span> <span class="nx">type</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns the hover style for the icon</span>
<span class="c">     * @return {string} the css class hover state</span>
<span class="c">     * @method getHoverStyle</span>
<span class="c">     */</span>
    <span class="nx">getHoverStyle</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span> 
        <span class="k">var</span> <span class="nx">s</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">getStyle</span><span class="o">();</span>
        <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">hasChildren</span><span class="o">(</span><span class="kc">true</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="o">.</span><span class="nx">isLoading</span><span class="o">)</span> <span class="o">{</span> 
            <span class="nx">s</span> <span class="o">+=</span> <span class="s2">&quot;h&quot;</span><span class="o">;</span> 
        <span class="o">}</span>
        <span class="k">return</span> <span class="nx">s</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Recursively expands all of this node&#39;s children.</span>
<span class="c">     * @method expandAll</span>
<span class="c">     */</span>
    <span class="nx">expandAll</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span> 
        <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">;</span><span class="nx">i</span><span class="o">&lt;</span><span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">.</span><span class="nx">length</span><span class="o">;++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">c</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
            <span class="k">if</span> <span class="o">(</span><span class="nx">c</span><span class="o">.</span><span class="nx">isDynamic</span><span class="o">())</span> <span class="o">{</span>
                <span class="nx">alert</span><span class="o">(</span><span class="s2">&quot;Not supported (lazy load + expand all)&quot;</span><span class="o">);</span>
                <span class="k">break</span><span class="o">;</span>
            <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(!</span> <span class="nx">c</span><span class="o">.</span><span class="nx">multiExpand</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">alert</span><span class="o">(</span><span class="s2">&quot;Not supported (no multi-expand + expand all)&quot;</span><span class="o">);</span>
                <span class="k">break</span><span class="o">;</span>
            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
                <span class="nx">c</span><span class="o">.</span><span class="nx">expand</span><span class="o">();</span>
                <span class="nx">c</span><span class="o">.</span><span class="nx">expandAll</span><span class="o">();</span>
            <span class="o">}</span>
        <span class="o">}</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Recursively collapses all of this node&#39;s children.</span>
<span class="c">     * @method collapseAll</span>
<span class="c">     */</span>
    <span class="nx">collapseAll</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span> 
        <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">;</span><span class="nx">i</span><span class="o">&lt;</span><span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">.</span><span class="nx">length</span><span class="o">;++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">collapse</span><span class="o">();</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">collapseAll</span><span class="o">();</span>
        <span class="o">}</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Configures this node for dynamically obtaining the child data</span>
<span class="c">     * when the node is first expanded.  Calling it without the callback</span>
<span class="c">     * will turn off dynamic load for the node.</span>
<span class="c">     * @method setDynamicLoad</span>
<span class="c">     * @param fmDataLoader {function} the function that will be used to get the data.</span>
<span class="c">     * @param iconMode {int} configures the icon that is displayed when a dynamic</span>
<span class="c">     * load node is expanded the first time without children.  By default, the </span>
<span class="c">     * &quot;collapse&quot; icon will be used.  If set to 1, the leaf node icon will be</span>
<span class="c">     * displayed.</span>
<span class="c">     */</span>
    <span class="nx">setDynamicLoad</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">fnDataLoader</span><span class="o">,</span> <span class="nx">iconMode</span><span class="o">)</span> <span class="o">{</span> 
        <span class="k">if</span> <span class="o">(</span><span class="nx">fnDataLoader</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">dataLoader</span> <span class="o">=</span> <span class="nx">fnDataLoader</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_dynLoad</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
        <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">dataLoader</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">_dynLoad</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="k">if</span> <span class="o">(</span><span class="nx">iconMode</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">iconMode</span> <span class="o">=</span> <span class="nx">iconMode</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Evaluates if this node is the root node of the tree</span>
<span class="c">     * @method isRoot</span>
<span class="c">     * @return {boolean} true if this is the root node</span>
<span class="c">     */</span>
    <span class="nx">isRoot</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span> 
        <span class="k">return</span> <span class="o">(</span><span class="k">this</span> <span class="o">==</span> <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">root</span><span class="o">);</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Evaluates if this node&#39;s children should be loaded dynamically.  Looks for</span>
<span class="c">     * the property both in this instance and the root node.  If the tree is</span>
<span class="c">     * defined to load all children dynamically, the data callback function is</span>
<span class="c">     * defined in the root node</span>
<span class="c">     * @method isDynamic</span>
<span class="c">     * @return {boolean} true if this node&#39;s children are to be loaded dynamically</span>
<span class="c">     */</span>
    <span class="nx">isDynamic</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span> 
        <span class="k">var</span> <span class="nx">lazy</span> <span class="o">=</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">isRoot</span><span class="o">()</span> <span class="o">&amp;&amp;</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">_dynLoad</span> <span class="o">||</span> <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">root</span><span class="o">.</span><span class="nx">_dynLoad</span><span class="o">));</span>
        <span class="c">// this.logger.log(&quot;isDynamic: &quot; + lazy);</span>
<span class="c"></span>        <span class="k">return</span> <span class="nx">lazy</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns the current icon mode.  This refers to the way childless dynamic</span>
<span class="c">     * load nodes appear.</span>
<span class="c">     * @method getIconMode</span>
<span class="c">     * @return {int} 0 for collapse style, 1 for leaf node style</span>
<span class="c">     */</span>
    <span class="nx">getIconMode</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">iconMode</span> <span class="o">||</span> <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">root</span><span class="o">.</span><span class="nx">iconMode</span><span class="o">);</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Checks if this node has children.  If this node is lazy-loading and the</span>
<span class="c">     * children have not been rendered, we do not know whether or not there</span>
<span class="c">     * are actual children.  In most cases, we need to assume that there are</span>
<span class="c">     * children (for instance, the toggle needs to show the expandable </span>
<span class="c">     * presentation state).  In other times we want to know if there are rendered</span>
<span class="c">     * children.  For the latter, &quot;checkForLazyLoad&quot; should be false.</span>
<span class="c">     * @method hasChildren</span>
<span class="c">     * @param checkForLazyLoad {boolean} should we check for unloaded children?</span>
<span class="c">     * @return {boolean} true if this has children or if it might and we are</span>
<span class="c">     * checking for this condition.</span>
<span class="c">     */</span>
    <span class="nx">hasChildren</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">checkForLazyLoad</span><span class="o">)</span> <span class="o">{</span> 
        <span class="k">return</span> <span class="o">(</span> <span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="m">0</span> <span class="o">||</span> 
                <span class="o">(</span><span class="nx">checkForLazyLoad</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">isDynamic</span><span class="o">()</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="o">.</span><span class="nx">dynamicLoadComplete</span><span class="o">)</span> <span class="o">);</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Expands if node is collapsed, collapses otherwise.</span>
<span class="c">     * @method toggle</span>
<span class="c">     */</span>
    <span class="nx">toggle</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">locked</span> <span class="o">&amp;&amp;</span> <span class="o">(</span> <span class="k">this</span><span class="o">.</span><span class="nx">hasChildren</span><span class="o">(</span><span class="kc">true</span><span class="o">)</span> <span class="o">||</span> <span class="k">this</span><span class="o">.</span><span class="nx">isDynamic</span><span class="o">())</span> <span class="o">)</span> <span class="o">{</span>
            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">expanded</span><span class="o">)</span> <span class="o">{</span> <span class="k">this</span><span class="o">.</span><span class="nx">collapse</span><span class="o">();</span> <span class="o">}</span> <span class="k">else</span> <span class="o">{</span> <span class="k">this</span><span class="o">.</span><span class="nx">expand</span><span class="o">();</span> <span class="o">}</span>
        <span class="o">}</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns the markup for this node and its children.</span>
<span class="c">     * @method getHtml</span>
<span class="c">     * @return {string} the markup for this node and its expanded children.</span>
<span class="c">     */</span>
    <span class="nx">getHtml</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>

        <span class="k">this</span><span class="o">.</span><span class="nx">childrenRendered</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>

        <span class="k">var</span> <span class="nx">sb</span> <span class="o">=</span> <span class="o">[];</span>
        <span class="nx">sb</span><span class="o">[</span><span class="nx">sb</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="s1">&#39;&lt;div class=&quot;ygtvitem&quot; id=&quot;&#39;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">getElId</span><span class="o">()</span> <span class="o">+</span> <span class="s1">&#39;&quot;&gt;&#39;</span><span class="o">;</span>
        <span class="nx">sb</span><span class="o">[</span><span class="nx">sb</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">getNodeHtml</span><span class="o">();</span>
        <span class="nx">sb</span><span class="o">[</span><span class="nx">sb</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">getChildrenHtml</span><span class="o">();</span>
        <span class="nx">sb</span><span class="o">[</span><span class="nx">sb</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="s1">&#39;&lt;/div&gt;&#39;</span><span class="o">;</span>
        <span class="k">return</span> <span class="nx">sb</span><span class="o">.</span><span class="nx">join</span><span class="o">(</span><span class="s2">&quot;&quot;</span><span class="o">);</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Called when first rendering the tree.  We always build the div that will</span>
<span class="c">     * contain this nodes children, but we don&#39;t render the children themselves</span>
<span class="c">     * unless this node is expanded.</span>
<span class="c">     * @method getChildrenHtml</span>
<span class="c">     * @return {string} the children container div html and any expanded children</span>
<span class="c">     * @private</span>
<span class="c">     */</span>
    <span class="nx">getChildrenHtml</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>

        <span class="k">var</span> <span class="nx">sb</span> <span class="o">=</span> <span class="o">[];</span>
        <span class="nx">sb</span><span class="o">[</span><span class="nx">sb</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="s1">&#39;&lt;div class=&quot;ygtvchildren&quot;&#39;</span><span class="o">;</span>
        <span class="nx">sb</span><span class="o">[</span><span class="nx">sb</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="s1">&#39; id=&quot;&#39;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">getChildrenElId</span><span class="o">()</span> <span class="o">+</span> <span class="s1">&#39;&quot;&#39;</span><span class="o">;</span>
        <span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">expanded</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">sb</span><span class="o">[</span><span class="nx">sb</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="s1">&#39; style=&quot;display:none;&quot;&#39;</span><span class="o">;</span>
        <span class="o">}</span>
        <span class="nx">sb</span><span class="o">[</span><span class="nx">sb</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="s1">&#39;&gt;&#39;</span><span class="o">;</span>

        <span class="c">// Don&#39;t render the actual child node HTML unless this node is expanded.</span>
<span class="c"></span>        <span class="k">if</span> <span class="o">(</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">hasChildren</span><span class="o">(</span><span class="kc">true</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="o">.</span><span class="nx">expanded</span><span class="o">)</span> <span class="o">||</span>
                <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">renderHidden</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="o">.</span><span class="nx">isDynamic</span><span class="o">())</span> <span class="o">)</span> <span class="o">{</span>
            <span class="nx">sb</span><span class="o">[</span><span class="nx">sb</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">renderChildren</span><span class="o">();</span>
        <span class="o">}</span>

        <span class="nx">sb</span><span class="o">[</span><span class="nx">sb</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="s1">&#39;&lt;/div&gt;&#39;</span><span class="o">;</span>

        <span class="k">return</span> <span class="nx">sb</span><span class="o">.</span><span class="nx">join</span><span class="o">(</span><span class="s2">&quot;&quot;</span><span class="o">);</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Generates the markup for the child nodes.  This is not done until the node</span>
<span class="c">     * is expanded.</span>
<span class="c">     * @method renderChildren</span>
<span class="c">     * @return {string} the html for this node&#39;s children</span>
<span class="c">     * @private</span>
<span class="c">     */</span>
    <span class="nx">renderChildren</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>

        <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;rendering children for &quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">index</span><span class="o">);</span>

        <span class="k">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>

        <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">isDynamic</span><span class="o">()</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="o">.</span><span class="nx">dynamicLoadComplete</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">isLoading</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">locked</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>

            <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">dataLoader</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Using dynamic loader defined for this node&quot;</span><span class="o">);</span>

                <span class="nx">setTimeout</span><span class="o">(</span> 
                    <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
                        <span class="nx">node</span><span class="o">.</span><span class="nx">dataLoader</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> 
                            <span class="k">function</span><span class="o">()</span> <span class="o">{</span> 
                                <span class="nx">node</span><span class="o">.</span><span class="nx">loadComplete</span><span class="o">();</span> 
                            <span class="o">});</span>
                    <span class="o">},</span> <span class="m">10</span><span class="o">);</span>
                
            <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">root</span><span class="o">.</span><span class="nx">dataLoader</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Using the tree-level dynamic loader&quot;</span><span class="o">);</span>

                <span class="nx">setTimeout</span><span class="o">(</span> 
                    <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
                        <span class="nx">node</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">root</span><span class="o">.</span><span class="nx">dataLoader</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> 
                            <span class="k">function</span><span class="o">()</span> <span class="o">{</span> 
                                <span class="nx">node</span><span class="o">.</span><span class="nx">loadComplete</span><span class="o">();</span> 
                            <span class="o">});</span>
                    <span class="o">},</span> <span class="m">10</span><span class="o">);</span>

            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
                <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;no loader found&quot;</span><span class="o">);</span>
                <span class="k">return</span> <span class="s2">&quot;Error: data loader not found or not specified.&quot;</span><span class="o">;</span>
            <span class="o">}</span>

            <span class="k">return</span> <span class="s2">&quot;&quot;</span><span class="o">;</span>

        <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
            <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">completeRender</span><span class="o">();</span>
        <span class="o">}</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Called when we know we have all the child data.</span>
<span class="c">     * @method completeRender</span>
<span class="c">     * @return {string} children html</span>
<span class="c">     */</span>
    <span class="nx">completeRender</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;completeRender: &quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">index</span> <span class="o">+</span> <span class="s2">&quot;, # of children: &quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">.</span><span class="nx">length</span><span class="o">);</span>
        <span class="k">var</span> <span class="nx">sb</span> <span class="o">=</span> <span class="o">[];</span>

        <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
            <span class="c">// this.children[i].childrenRendered = false;</span>
<span class="c"></span>            <span class="nx">sb</span><span class="o">[</span><span class="nx">sb</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">children</span><span class="o">[</span><span class="nx">i</span><span class="o">].</span><span class="nx">getHtml</span><span class="o">();</span>
        <span class="o">}</span>
        
        <span class="k">this</span><span class="o">.</span><span class="nx">childrenRendered</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>

        <span class="k">return</span> <span class="nx">sb</span><span class="o">.</span><span class="nx">join</span><span class="o">(</span><span class="s2">&quot;&quot;</span><span class="o">);</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Load complete is the callback function we pass to the data provider</span>
<span class="c">     * in dynamic load situations.</span>
<span class="c">     * @method loadComplete</span>
<span class="c">     */</span>
    <span class="nx">loadComplete</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;loadComplete: &quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">index</span><span class="o">);</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">getChildrenEl</span><span class="o">().</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">completeRender</span><span class="o">();</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">dynamicLoadComplete</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">isLoading</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">expand</span><span class="o">();</span>
        <span class="k">this</span><span class="o">.</span><span class="nx">tree</span><span class="o">.</span><span class="nx">locked</span> <span class="o">=</span> <span class="kc">false</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns this node&#39;s ancestor at the specified depth.</span>
<span class="c">     * @method getAncestor</span>
<span class="c">     * @param {int} depth the depth of the ancestor.</span>
<span class="c">     * @return {Node} the ancestor</span>
<span class="c">     */</span>
    <span class="nx">getAncestor</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">depth</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(</span><span class="nx">depth</span> <span class="o">&gt;=</span> <span class="k">this</span><span class="o">.</span><span class="nx">depth</span> <span class="o">||</span> <span class="nx">depth</span> <span class="o">&lt;</span> <span class="m">0</span><span class="o">)</span>  <span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;illegal getAncestor depth: &quot;</span> <span class="o">+</span> <span class="nx">depth</span><span class="o">);</span>
            <span class="k">return</span> <span class="kc">null</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="k">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">parent</span><span class="o">;</span>
        
        <span class="k">while</span> <span class="o">(</span><span class="nx">p</span><span class="o">.</span><span class="nx">depth</span> <span class="o">&gt;</span> <span class="nx">depth</span><span class="o">)</span> <span class="o">{</span>
            <span class="nx">p</span> <span class="o">=</span> <span class="nx">p</span><span class="o">.</span><span class="nx">parent</span><span class="o">;</span>
        <span class="o">}</span>

        <span class="k">return</span> <span class="nx">p</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Returns the css class for the spacer at the specified depth for</span>
<span class="c">     * this node.  If this node&#39;s ancestor at the specified depth</span>
<span class="c">     * has a next sibling the presentation is different than if it</span>
<span class="c">     * does not have a next sibling</span>
<span class="c">     * @method getDepthStyle</span>
<span class="c">     * @param {int} depth the depth of the ancestor.</span>
<span class="c">     * @return {string} the css class for the spacer</span>
<span class="c">     */</span>
    <span class="nx">getDepthStyle</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">depth</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">getAncestor</span><span class="o">(</span><span class="nx">depth</span><span class="o">).</span><span class="nx">nextSibling</span><span class="o">)</span> <span class="o">?</span> 
            <span class="s2">&quot;ygtvdepthcell&quot;</span> <span class="o">:</span> <span class="s2">&quot;ygtvblankdepthcell&quot;</span><span class="o">;</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Get the markup for the node.  This is designed to be overrided so that we can</span>
<span class="c">     * support different types of nodes.</span>
<span class="c">     * @method getNodeHtml</span>
<span class="c">     * @return {string} The HTML that will render this node.</span>
<span class="c">     */</span>
    <span class="nx">getNodeHtml</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span> 
        <span class="k">this</span><span class="o">.</span><span class="nx">logger</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s2">&quot;Generating html&quot;</span><span class="o">);</span>
        <span class="k">return</span> <span class="s2">&quot;&quot;</span><span class="o">;</span> 
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Regenerates the html for this node and its children.  To be used when the</span>
<span class="c">     * node is expanded and new children have been added.</span>
<span class="c">     * @method refresh</span>
<span class="c">     */</span>
    <span class="nx">refresh</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="c">// this.loadComplete();</span>
<span class="c"></span>        <span class="k">this</span><span class="o">.</span><span class="nx">getChildrenEl</span><span class="o">().</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">completeRender</span><span class="o">();</span>

        <span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">hasIcon</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">var</span> <span class="nx">el</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">getToggleEl</span><span class="o">();</span>
            <span class="k">if</span> <span class="o">(</span><span class="nx">el</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">el</span><span class="o">.</span><span class="nx">className</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">getStyle</span><span class="o">();</span>
            <span class="o">}</span>
        <span class="o">}</span>
    <span class="o">},</span>

    <span class="c">/**</span>
<span class="c">     * Node toString</span>
<span class="c">     * @method toString</span>
<span class="c">     * @return {string} string representation of the node</span>
<span class="c">     */</span>
    <span class="nx">toString</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="s2">&quot;Node (&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="o">.</span><span class="nx">index</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span><span class="o">;</span>
    <span class="o">}</span>

<span class="o">};</span>

<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">augment</span><span class="o">(</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">widget</span><span class="o">.</span><span class="nx">Node</span><span class="o">,</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">EventProvider</span><span class="o">);</span>
</pre></div>
                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div class="module">
                        <h4>Modules</h4>
                        <ul class="content">

                                <li class=""><a href="module_animation.html">animation</a></li>

                                <li class=""><a href="module_autocomplete.html">autocomplete</a></li>

                                <li class=""><a href="module_button.html">button</a></li>

                                <li class=""><a href="module_calendar.html">calendar</a></li>

                                <li class=""><a href="module_connection.html">connection</a></li>

                                <li class=""><a href="module_container.html">container</a></li>

                                <li class=""><a href="module_datasource.html">datasource</a></li>

                                <li class=""><a href="module_datatable.html">datatable</a></li>

                                <li class=""><a href="module_dom.html">dom</a></li>

                                <li class=""><a href="module_dragdrop.html">dragdrop</a></li>

                                <li class=""><a href="module_element.html">element</a></li>

                                <li class=""><a href="module_event.html">event</a></li>

                                <li class=""><a href="module_history.html">history</a></li>

                                <li class=""><a href="module_logger.html">logger</a></li>

                                <li class=""><a href="module_menu.html">menu</a></li>

                                <li class=""><a href="module_slider.html">slider</a></li>

                                <li class=""><a href="module_tabview.html">tabview</a></li>

                                <li class="selected"><a href="module_treeview.html">treeview</a></li>

                                <li class=""><a href="module_yahoo.html">yahoo</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="YAHOO.widget.HTMLNode.html">YAHOO.widget.HTMLNode</a></li>
                                <li class=""><a href="YAHOO.widget.MenuNode.html">YAHOO.widget.MenuNode</a></li>
                                <li class=""><a href="YAHOO.widget.Node.html">YAHOO.widget.Node</a></li>
                                <li class=""><a href="YAHOO.widget.RootNode.html">YAHOO.widget.RootNode</a></li>
                                <li class=""><a href="YAHOO.widget.TextNode.html">YAHOO.widget.TextNode</a></li>
                                <li class=""><a href="YAHOO.widget.TreeView.html">YAHOO.widget.TreeView</a></li>
                                <li class=""><a href="YAHOO.widget.TVAnim.html">YAHOO.widget.TVAnim</a></li>
                                <li class=""><a href="YAHOO.widget.TVFadeIn.html">YAHOO.widget.TVFadeIn</a></li>
                                <li class=""><a href="YAHOO.widget.TVFadeOut.html">YAHOO.widget.TVFadeOut</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class=""><a href="HTMLNode.js.html">HTMLNode.js</a></li>
                                <li class=""><a href="MenuNode.js.html">MenuNode.js</a></li>
                                <li class="selected"><a href="Node.js.html">Node.js</a></li>
                                <li class=""><a href="RootNode.js.html">RootNode.js</a></li>
                                <li class=""><a href="TextNode.js.html">TextNode.js</a></li>
                                <li class=""><a href="TreeView.js.html">TreeView.js</a></li>
                                <li class=""><a href="TVAnim.js.html">TVAnim.js</a></li>
                                <li class=""><a href="TVFadeIn.js.html">TVFadeIn.js</a></li>
                                <li class=""><a href="TVFadeOut.js.html">TVFadeOut.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2007 Yahoo! Inc. All rights reserved.
	</div>
</div>
</body>
</html>
